package protocol.SZ_2021;

import java.util.HashMap;

public class Handle2021SZ80 implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x01:
                return handle8001(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }



    private String handle8001(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:中心通用应答");
        builder.append("\r\n");
        builder.append("应答流水号："+cmd.readBCD(2));
        builder.append("\r\n");
        builder.append("应答ID："+cmd.readBCD(2));
        builder.append("\r\n");

        HashMap<Integer,String> resMap = new HashMap<>();
        resMap.put(0,"成功/确认");
        resMap.put(1,"失败");
        resMap.put(2,"消息有误");

        int res = cmd.readInt(1);
        builder.append("结果（"+res+"):"+resMap.getOrDefault(res,"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

}
